#include <stdio.h>
#include <stdlib.h>
#include "io.h"
#include "JacobisMethod.h"

#define TIMER
//#define DEBUG_XN

int main(int argc, char* argv[]){
    struct extendedMatrix *matrix;
    unsigned long i, N;
    double *X;
    
    #ifdef TIMER
        struct timeval t_zero, t_final;
        double delta_t;   
        gettimeofday(&t_zero, NULL);
    #endif 

    if(argc!=2){
        printf("Entrada incorreta\n");
        exit(-1);
    }

    matrix = readMatrix(argv[1]);
    
    X = JacobisMethod(matrix);

    #ifdef DEBUG_XN
        if(X!=NULL){
            N = matrix->J_ORDER;
            for(i=0; i<N; i++){
                printf("x%lu = %lf \n", i, X[i]);
            }
        }else printf("X = NULL\n");
    #endif

    freeMatrix(matrix);

    #ifdef TIMER
        gettimeofday(&t_final, NULL);
        delta_t = t_final.tv_sec - t_zero.tv_sec +
        ( t_final.tv_usec - t_zero.tv_usec ) / 1e6;
        printf("Tempo = %.3lf segundos\n", delta_t);    
    #endif

    return 0;  
}

